(in-package :cl-gdbm)

#+nil
(eval-when (:load-toplevel)
  (uffi:load-foreign-library (merge-pathnames *load-pathname*
					      #p"cl-gdbm-stub.so")
			     :module "cl-gdbm-stub.so"
			     :supporting-libraries '("c")))

(defconstant GDBM_READER 0)
(defconstant GDBM_WRITER 1)
(defconstant GDBM_WRCREAT 2)
(defconstant GDBM_NEWDB 3)
(defconstant GDBM_FAST #x10)		; OBSOLETE
(defconstant GDBM_SYNC #x20)
(defconstant GDBM_NOLOCK #x40)
(defconstant GDBM_INSERT 0)
(defconstant GDBM_REPLACE 1)
(defconstant GDBM_CACHESIZE 1)
(defconstant GDBM_FASTMODE 2)		; OBSOLETE
(defconstant GDBM_SYNCMODE 3)
(defconstant GDBM_CENTFREE 4)
(defconstant GDBM_COALESCEBLKS 5)

(def-function ("open_file" gdbm-open-file)
    ((name :cstring)
     (block-size :int)
     (read-write :int)
     (mode :int))
  :returning :pointer-void
  :module "cl-gdbm-stub.so")

(def-function ("close_file" gdbm-close-file)
    ((file :pointer-void))
  :returning :void
  :module "cl-gdbm-stub.so")

(def-function ("store" gdbm-store)
    ((file :pointer-void)
     (key :cstring)
     (data :cstring)
     (flag :int))
  :returning :int
  :module "cl-gdbm-stub.so")

(def-function ("fetch" gdbm-fetch)
    ((file :pointer-void)
     (key :cstring))
  :returning (* :char)
  :module "cl-gdbm-stub.so")

(def-function ("existsp" gdbm-exists-p)
    ((file :pointer-void)
     (key :cstring))
  :returning :int
  :module "cl-gdbm-stub.so")

(def-function ("delete" gdbm-delete)
    ((file :pointer-void)
     (key :cstring))
  :returning :int
  :module "cl-gdbm-stub.so")

(def-function ("reorganize" gdbm-reorganize)
    ((file :pointer-void))
  :returning :int
  :module "cl-gdbm-stub.so")

(def-function ("sync" gdbm-sync)
    ((file :pointer-void))
  :returning :int
  :module "cl-gdbm-stub.so")

(def-function ("firstkey" gdbm-first-key)
    ((file :pointer-void))
  :returning (* :char)
  :module "cl-gdbm-stub.so")

(def-function ("nextkey" gdbm-next-key)
    ((file :pointer-void)
     (key :cstring))
  :returning (* :char)
  :module "cl-gdbm-stub.so")

(def-function ("set_cachesize" gdbm-set-cachesize)
    ((file :pointer-void)
     (size :int))
  :returning :int
  :module "cl-gdbm-stub.so")

(def-function ("set_syncmode" gdbm-set-syncmode)
    ((file :pointer-void)
     (state :int))
  :returning :int
  :module "cl-gdbm-stub.so")